﻿using UnityEngine;

namespace HBFramework
{
    /// <summary>
    /// Panel信息类
    /// </summary>
    public class PanelInfo
    {
        public BasePanel basePanel;
        public Canvas canvas;
        public GameObject go;

        private float hideTime;

        public PanelInfo(BasePanel uibase, Canvas canvas, GameObject go)
        {
            this.basePanel = uibase;
            this.canvas = canvas;
            this.go = go;
        }

        public void Show()
        {
            basePanel.OnShow();
            hideTime = 0;
            canvas.enabled = true;
        }

        public void Hide()
        {
            basePanel.OnHide();
            canvas.enabled = false;
            hideTime = 0;
        }

        public void Destroy()
        {
            basePanel.OnRelease();
            GameObject.Destroy(canvas.gameObject);
        }

        public bool Refresh()
        {
            if (basePanel.RemainTime == -1)
            {
                return false;
            }
            hideTime += Time.deltaTime;
            if (hideTime >= basePanel.RemainTime)
            {
                Destroy();
                return true;
            }
            return false;
        }
    }
}
